---
sidebar_label: Computed fields
sidebar_position: 7
description: Manage computed fields with the Hasura schema/Metadata API
keywords:
  - hasura
  - docs
  - schema/Metadata API
  - API reference
  - computed field
---

# Schema/Metadata API Reference: Computed Fields (Deprecated)

:::caution Deprecation

In versions `v2.0.0` and above, the schema/Metadata API is deprecated in
favour of the [schema API](/api-reference/schema-api/index.mdx) and the
[Metadata API](/api-reference/metadata-api/index.mdx).

Though for backwards compatibility, the schema/Metadata APIs will
continue to function.

:::

## Introduction

**computed field** is an extra field added to a table, its value is
computed via an SQL function which has the table row type as an input
argument. Currently, the Hasura GraphQL Engine supports functions
returning [base types](https://www.postgresql.org/docs/current/extend-type-system.html#id-1.8.3.5.9)
or [table row types](https://www.postgresql.org/docs/current/rowtypes.html#ROWTYPES-DECLARING)
as computed fields.

## add_computed_field {#schema-metadata-add-computed-field}

`add_computed_field` is used to define a computed field in a table.
There cannot be an existing column or relationship or computed field
with the same name.

Create a `computed field` called `full_name` on an `author` _table_,
using an SQL function called `author_full_name`:

```http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type":"add_computed_field",
    "args":{
        "table":{
            "name":"author",
            "schema":"public"
        },
        "name":"full_name",
        "definition":{
            "function":{
                "name":"author_full_name",
                "schema":"public"
            },
            "table_argument":"author_row"
        }
    }
}
```

### Args syntax {#schema-metadata-add-computed-field-syntax}

| Key        | Required | Schema                                                                            | Description                    |
| ---------- | -------- | --------------------------------------------------------------------------------- | ------------------------------ |
| table      | true     | [TableName](/api-reference/syntax-defs.mdx#tablename)                             | Name of the table              |
| name       | true     | [ComputedFieldName](/api-reference/syntax-defs.mdx#computedfieldname)             | Name of the new computed field |
| definition | true     | [ComputedFieldDefinition](/api-reference/syntax-defs.mdx#computedfielddefinition) | The computed field definition  |
| comment    | false    | text                                                                              | comment                        |

## drop_computed_field {#schema-metadata-drop-computed-field}

`drop_computed_field` is used to drop a computed field of a table. If
there are other objects dependent on this computed field, like
permissions, the request will fail and report the dependencies unless
`cascade` is set to `true`. If `cascade` is set to `true`, the dependent
objects are also dropped.

Drop a computed field `full_name` from a table `author`:

```http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type":"drop_computed_field",
    "args":{
        "table":{
            "name":"author",
            "schema":"public"
        },
        "name":"full_name",
        "cascade": false
    }
}
```

### Args syntax {#schema-metadata-drop-computed-field-syntax}

| Key     | Required | Schema                                                                | Description                                                                                   |
| ------- | -------- | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| table   | true     | [TableName](/api-reference/syntax-defs.mdx#tablename)                 | Name of the table                                                                             |
| name    | true     | [ComputedFieldName](/api-reference/syntax-defs.mdx#computedfieldname) | Name of the computed field                                                                    |
| cascade | false    | Boolean                                                               | When set to `true`, all the dependent items (if any) on this computed fields are also dropped |
